package common.qiniu

import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject

data class SafeResult(
        val code: Int,
        val rate: Double,
        val label: Int,
        val name: String,
        val review: Boolean
){
    companion object{
        fun fromJson(json: String?): SafeResult?{
            if (json == null) return null
            val jObj = JSON.parseObject(json)
            val code = jObj.getInteger("code")
            val result = jObj.getJSONArray("fileList")[0] as JSONObject
            return SafeResult(
                    code = code,
                    rate = result.getDouble("rate"),
                    label = result.getIntValue("label"),
                    name = result.getString("name"),
                    review = result.getBoolean("review")
            )
        }
    }

    fun isSuccess(): Boolean{
        return code == 0
    }
}
